
#include <iostream>
#include <string>
#include <regex>


int main()
{
    std::string str = "PUT /what/login HTTP/1.1\r\n";
    // std::string str = "PUT /what/login?user=xiaoming&passwd=123123 HTTP/1.1\r\n";
    std::smatch matches;
    std::regex e("(GET|HEAD|POST|PUT|DELETE) ([^?]*)(?:\\?(.*))? (HTTP/\\d{1}\\.\\d{1})(?:\n|\r\n)?");

    bool ret = std::regex_match(str, matches, e);
    if (ret == false) 
    {
        std::cout << "匹配失败" << std::endl;
        return -1;
    }

    int i = 0;
    for (auto& a : matches)
    {
        std::cout << i << ": " << a << std::endl;
        ++i;
    }

    return 0;
}